The Spellcraft loci system is the core architecture behind spell creation, bundling, and verification in Magi CLI. It consists of three main components: SpellBundle, Sigildry, and SpellParser, all working together to create and manage secure, verifiable spell packages.
The central class for creating and managing spell bundles.
.spell
bundlesspell_name.spell/
├── spell/
│ ├── spell.yaml # Spell configuration
│ └── main.py/main.sh # Entry point
├── artifacts/ # Additional resources
├── spell.json # Bundle metadata
└── spell_name_sigil.svg # Verification sigil
create_bundle()
: Package a spell directory into a .spell
bundleextract_bundle()
: Unpack a .spell
bundle for executionverify_assets()
: Check bundle integrityload_config()
: Parse spell configurationHandles cryptographic verification and visual representation of spells.
generate_sigil()
: Create new spell sigilverify_sigil()
: Check sigil authenticitygenerate_sigil_hash()
: Create unique spell identifiercheck_spell_conflict()
: Verify spell uniquenessManages spell parsing, execution, and dependency handling.
parse_bundle()
: Extract and validate spell contentsexecute_spell_file()
: Run spell with proper environmentcheck_dependencies()
: Verify and install requirementsfind_spell_file()
: Locate spells in the systemgraph TD
A[User Input] --> B[SpellBuilder]
B --> C[SpellBundle]
C --> D[Sigildry]
D --> E[Bundle Creation]
E --> F[Verification]
graph TD
A[Cast Command] --> B[SpellParser]
B --> C[Bundle Verification]
C --> D[Dependency Check]
D --> E[Environment Setup]
E --> F[Spell Execution]
class SpellBundle:
def create_bundle(self, destination_dir: Path) -> Path:
"""Create a spell bundle with verification."""
# Verify configuration
config = self.load_config()
self.verify_assets()
# Generate sigil
sigil_hash, sigil_path = self._generate_spell_sigil(config)
# Update configuration
config['sigil_hash'] = sigil_hash
# Create bundle
bundle_path = destination_dir / f"{config['name']}.spell"
with zipfile.ZipFile(bundle_path, 'w') as zf:
# Add metadata
metadata = self._generate_metadata(config)
zf.writestr('spell.json', json.dumps(metadata))
# Add spell contents
self._add_spell_contents(zf)
# Add sigil
zf.write(sigil_path, sigil_path.name)
return bundle_path
class Sigildry:
def generate_sigil(self, hash_input: str, output_path: Path) -> None:
"""Generate a spell sigil SVG."""
# Create SVG canvas
dwg = svgwrite.Drawing(output_path, size=(256, 256))
# Generate design elements from hash
params = self._hash_to_params(hash_input)
# Add visual elements
self._generate_outer_rim(dwg, hash_input)
self._generate_starburst(dwg, hash_input, params)
self._generate_center_rune(dwg, hash_input)
# Save sigil
dwg.save()
class SpellParser:
def execute_spell_file(self, spell_name: str, *args, verbose: bool = False) -> bool:
"""Execute a spell with proper environment setup."""
try:
# Locate and parse spell
spell_path = self.find_spell_file(spell_name)
temp_dir, metadata = self.parse_bundle(spell_path)
# Verify sigil
if not self.verify_sigil(spell_path):
raise SecurityError("Invalid spell sigil")
# Check dependencies
if not self.check_dependencies(metadata.get('dependencies', {})):
raise DependencyError("Missing requirements")
# Execute spell
return self._run_spell(temp_dir, metadata, args)
except Exception as e:
if verbose:
self._log_error(e)
return False